# 1 "../Codes/MCU_Mold/MCU_TimeManager.c"
# 1 "E:\\APT_Landscape_mode\\APT32F1023_New\\Source//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "../Codes/MCU_Mold/MCU_TimeManager.c"

# 1 "../Codes/MCU_Mold/MCU_TimeManager.h" 1
# 19 "../Codes/MCU_Mold/MCU_TimeManager.h"
# 1 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 1 3 4
# 21 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 3 4
# 1 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\csky-elfabiv2\\sys-include\\features.h" 1 3 4
# 22 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 2 3 4
# 1 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\csky-elfabiv2\\sys-include\\ansidef.h" 1 3 4
# 23 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 2 3 4


# 1 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stddef.h" 1 3 4
# 216 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stddef.h" 3 4

# 216 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stddef.h" 3 4
typedef unsigned int size_t;
# 26 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 2 3 4
# 1 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stdarg.h" 1 3 4
# 40 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 99 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include\\stdarg.h" 3 4
typedef __gnuc_va_list va_list;
# 27 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 2 3 4
# 38 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 3 4
typedef signed long fpos_t;


struct __stdio_file;
typedef struct __stdio_file FILE;
# 66 "d:\\c-sky\\cdkrepo\\toolchain\\ckv2elfminilib\\v3.10.32\\r\\lib\\gcc\\csky-elfabiv2\\6.3.0\\include-fixed\\stdio.h" 3 4
extern FILE *stdin, *stdout, *stderr;





extern int remove(char *filename);
extern int rename(const char *oldname, const char *newname);
extern FILE *tmpfile(void);
extern char *tmpnam(char *sptr);
extern FILE *fopen(const char *filename, const char *type);
extern FILE *freopen(const char *filename, const char *type, FILE *fp);
extern int fflush(FILE *stream);
extern int fclose(FILE *stream);
extern void setbuf(FILE *stream, char *buf);
extern int setvbuf(FILE *stream, char *buf, int type, size_t size);
extern int printf(const char *format, ...);
extern int fprintf(FILE *stream, const char *format, ...);
extern int sprintf(char *string, const char *format, ...);
extern int fnprintf(FILE *str,size_t size, const char *format,...);
extern int scanf(const char *format, ...);
extern int fscanf(FILE *stream, const char *format, ...);
extern int sscanf(const char *str, const char *format, ...);
extern int vfscanf(FILE * stream, const char * format, __gnuc_va_list arg_ptr);
extern int vscanf( const char * format, __gnuc_va_list ap);
extern int vsscanf(const char * str, const char * format, __gnuc_va_list arg_ptr);
extern int vprintf(const char *, __gnuc_va_list);
extern int vsprintf( char * str, const char * format, __gnuc_va_list arg_ptr);
extern int vsnprintf(char * str, size_t length, const char * format, __gnuc_va_list arg_ptr);
extern int vfprintf(FILE *stream, const char *format, __gnuc_va_list ap);
extern int snprintf(char *str, size_t size, const char *format, ...);
extern int fgetc(FILE *stream);
extern char *fgets(char *string,int n, FILE *stream);
extern char *gets(char *s);
extern int fputc(int ch, FILE *stream);
extern int fputs(const char *string, FILE *stream);
extern int getc(FILE *stream);
extern int putc(int c, FILE *stream);
extern int putchar(int ch);
extern int puts(const char *string);
extern int ungetc(int c, FILE *stream);
extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
extern size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
extern int fseek(FILE *stream, long offset, int fromwhere);
extern long ftell(FILE *stream);
extern void rewind(FILE *stream);
extern int fgetpos(FILE *stream, fpos_t *fileops);
extern int fsetpos(FILE *stream, const fpos_t *pos);
extern void clearerr(FILE *stream);
extern int feof(FILE *stream);
extern int ferror(FILE *stream);
extern void perror(const char *string);

extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2);
extern int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase);
extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase);


extern int getchar (void);
extern FILE *fdopen (int __fd, __const char *__modes);
extern int fileno (FILE *__stream);
# 20 "../Codes/MCU_Mold/MCU_TimeManager.h" 2

# 1 "../Codes/Y36_LCD_horizontal/typed.h" 1






# 6 "../Codes/Y36_LCD_horizontal/typed.h"
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;

typedef unsigned short uint16_t;

typedef unsigned long long uint64_t;
# 1 "include/apt32f102_ck801.h" 1
# 85 "include/apt32f102_ck801.h"
typedef enum IRQn
{

        ISR_Restart = -32,
        ISR_Misaligned_Access = -31,
        ISR_Access_Error = -30,
        ISR_Divided_By_Zero = -29,
        ISR_Illegal = -28,
        ISR_Privlege_Violation = -27,
        ISR_Trace_Exection = -26,
        ISR_Breakpoint_Exception = -25,
        ISR_Unrecoverable_Error = -24,
        ISR_Idly4_Error = -23,
        ISR_Auto_INT = -22,
        ISR_Auto_FINT = -21,
        ISR_Reserved_HAI = -20,
        ISR_Reserved_FP = -19,
        ISR_TLB_Ins_Empty = -18,
        ISR_TLB_Data_Empty = -17,

        INTC_CORETIM_IRQn = 0,
        INTC_TIME1_IRQn = 1,
        INTC_UART0_IRQn = 2,
        INTC_GPIOA2_IRQn = 8,
} IRQn_Type;


void INTC_Init(void);
void force_interrupt(IRQn_Type IRQn);

void CK_CPU_EnAllNormalIrq(void);
void CK_CPU_DisAllNormalIrq(void);
# 15 "../Codes/Y36_LCD_horizontal/typed.h" 2
# 22 "../Codes/MCU_Mold/MCU_TimeManager.h" 2



typedef void (*TimeRegHandleFptr)(void);
typedef struct
{
    TimeRegHandleFptr funptr;
    unsigned int TimeReg;
    unsigned int funcdoCount;
    char LoopCan;
    unsigned char Trigger;
}TimeRegObj;
typedef struct
{
    TimeRegObj TimeRegObjHandle[20];
    int TimeRegObjCountMs[20];
    int TimeRegObjCountMsTemp[20];

} TimeManager;

typedef void (*TimeHandle)(void);

void TimeManagerCreate(TimeManager *base);

void TimeManagerScanTimeMs(TimeManager *base, int freq_ms);

void TimeManagerScan(TimeManager *base);

TimeRegObj *TimeManagerCheck(TimeManager *base, TimeRegObj *obj);

void TimeManagerDelAll(TimeManager *base);

void TimeManagerUpdataTime(TimeManager *base, TimeRegObj *obj, int time);

unsigned char TimeManagerCheckTimeIsOver(TimeManager *base, TimeRegObj *obj);


TimeRegObj *TimeRegObjCreate(void (*Handle)(), int time, TimeManager *Manager);

void TimeRegObjDestory(TimeManager *base, TimeRegObj *obj);

void TimeRegObjUpdataTime(TimeManager *Manager, TimeRegObj *obj, int time);

void TimeManager_RunCount(TimeRegObj *obj, int count);

void TimeManagerDelete(TimeManager *base, TimeRegObj *obj);
# 3 "../Codes/MCU_Mold/MCU_TimeManager.c" 2


void TimeManagerCreate(TimeManager* base)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base != 
# 10 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 10 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   )
    {
        length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
        for (i = 0; i < length; i++)
        {
            base->TimeRegObjCountMs[i] = 0;
            base->TimeRegObjCountMsTemp[i] = 0;
            base->TimeRegObjHandle[i].TimeReg = 0;
            base->TimeRegObjHandle[i].funcdoCount = 0;
            base->TimeRegObjHandle[i].LoopCan = 0;
            base->TimeRegObjHandle[i].funptr = 0;
        }
    }
}

static unsigned char TimeManagerAdd(TimeManager *base, TimeRegObj *obj)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if ((base != 0) && (0 != obj))
    {
        length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
        for (i = 0; i < length; i++)
        {
            if (base->TimeRegObjHandle[i].funptr == obj->funptr)
            {

                return 'r';
            }
            if (0 == base->TimeRegObjHandle[i].funptr)
            {
                base->TimeRegObjHandle[i].funptr = obj->funptr;
                base->TimeRegObjHandle[i].LoopCan = obj->LoopCan;
                base->TimeRegObjHandle[i].TimeReg = obj->TimeReg;
                base->TimeRegObjCountMs[i] = obj->TimeReg;
                return 'k';
            }
        }
        return 'n';
    }
    return 'n';
}

void TimeManagerScanTimeMs(TimeManager *base, int freq_ms)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base != 
# 59 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 59 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   )
    {
        length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
        for (i = 0; i < length; i++)
        {
            if ((base->TimeRegObjHandle[i].funptr) != 
# 64 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                                                     0
# 64 "../Codes/MCU_Mold/MCU_TimeManager.c"
                                                         )
            {
                if (base->TimeRegObjCountMs[i] > 0) base->TimeRegObjCountMs[i] -= freq_ms;
                if ((base->TimeRegObjCountMs[i] == 0) || (base->TimeRegObjCountMs[i] < 0))
                {
                    base->TimeRegObjHandle[i].Trigger = 1;
                    base->TimeRegObjCountMs[i] = base->TimeRegObjHandle[i].TimeReg;
                }
            }
        }
    }
}

void TimeManagerScan(TimeManager *base)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base == 
# 82 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 82 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   ) return;
    length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
    for (i = 0; i < length; i++)
    {
        if ((base->TimeRegObjHandle[i].funptr) != 
# 86 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                                                 0
# 86 "../Codes/MCU_Mold/MCU_TimeManager.c"
                                                     )
        {
            if (base->TimeRegObjHandle[i].Trigger == 0) continue;
            base->TimeRegObjHandle[i].Trigger = 0;
            if ('k' == base->TimeRegObjHandle[i].LoopCan)
            {
                ((TimeRegHandleFptr)(base->TimeRegObjHandle[i].funptr))();
            }
            else if ('n' == base->TimeRegObjHandle[i].LoopCan)
            {
                if (base->TimeRegObjHandle[i].funcdoCount == 0) continue;
                if ((TimeRegHandleFptr *)(base->TimeRegObjHandle[i].funptr) != 0)
                {
                    ((TimeRegHandleFptr)(base->TimeRegObjHandle[i].funptr))();
                    base->TimeRegObjHandle[i].funcdoCount--;
                    base->TimeRegObjCountMs[i] = base->TimeRegObjHandle[i].TimeReg;
                }
                if ((base->TimeRegObjHandle[i].funcdoCount) == 0)
                {
                    TimeManagerDelete(base, (TimeRegObj *)&(base->TimeRegObjHandle[i]));
                }
            }
        }
    }
}

TimeRegObj *TimeManagerCheck(TimeManager *base, TimeRegObj *obj)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if ((base != 0) && (0 != obj))
    {
        length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
        for (i = 0; i < length; i++)
        {
            if (base->TimeRegObjHandle[i].funptr == obj->funptr)
            {
                return &base->TimeRegObjHandle[i];
            }
        }
        return 0;
    }
    return 0;
}

unsigned char TimeManagerCheckTimeIsOver(TimeManager *base, TimeRegObj *obj)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base == 0) return 'n';
    if (obj == 0) return 'n';
    length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
    if (0 != TimeManagerCheck(base, obj))
    {
        for (i = 0; i < length; i++)
        {
            if (base->TimeRegObjHandle[i].funptr == obj->funptr)
            {
                if ('k' == base->TimeRegObjHandle[i].LoopCan)
                {
                    if (base->TimeRegObjCountMs[i] > 0)
                    {
                        return 'n';
                    }
                    else
                    {
                        return 'k';
                    }
                }
                else if ('n' == base->TimeRegObjHandle[i].LoopCan)
                {
                    if (0 == base->TimeRegObjHandle[i].funcdoCount) return 'n';
                    return 'k';
                }
            }
        }
    }
    return 'n';
}

void TimeManagerDelete(TimeManager *base, TimeRegObj *obj)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base == 
# 173 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 173 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   ) return;
    if (obj == 
# 174 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 174 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  ) return;
    length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
    for (i = 0; i < length; i++)
    {
        if (&base->TimeRegObjHandle[i] == obj)
        {
            base->TimeRegObjHandle[i].funptr = 0;
            base->TimeRegObjHandle[i].LoopCan = 0;
            base->TimeRegObjCountMs[i] = 0;
            base->TimeRegObjCountMsTemp[i] = 0;
        }
    }
}

void TimeManagerDelAll(TimeManager *base)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base == 
# 193 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 193 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   ) return;
    length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
    for (i = 0; i < length; i++)
    {
        if (base->TimeRegObjHandle[i].funptr != 
# 197 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                                               0
# 197 "../Codes/MCU_Mold/MCU_TimeManager.c"
                                                   )
        {
            TimeRegObjDestory(base, &base->TimeRegObjHandle[i]);
            base->TimeRegObjHandle[i].funptr = 
# 200 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                                              0
# 200 "../Codes/MCU_Mold/MCU_TimeManager.c"
                                                  ;
            base->TimeRegObjCountMs[i] = 0;
        }
    }
}
void TimeManagerUpdataTime(TimeManager *base, TimeRegObj *obj, int time)
{
    unsigned char i = 0;
    unsigned char length = 0;

    if (base == 
# 210 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
               0
# 210 "../Codes/MCU_Mold/MCU_TimeManager.c"
                   ) return;
    if (obj == 
# 211 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 211 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  ) return;
    length = sizeof(base->TimeRegObjHandle) / sizeof(base->TimeRegObjHandle[0]);
    for (i = 0; i < length; i++)
    {
        if (&base->TimeRegObjHandle[i] == obj)
        {
            base->TimeRegObjCountMs[i] = time;
            base->TimeRegObjCountMsTemp[i] = 0;
        }
    }
}

TimeRegObj* TimeRegObjCreate(void (*Handle)(), int time, TimeManager *Manager)
{
    TimeRegObj obj;
    TimeRegObj* ret_obj;
    unsigned char res = 0;

    obj.funptr = (TimeRegHandleFptr)Handle;
    obj.TimeReg = time;
    obj.LoopCan = 'k';
    if ((0 == Handle) || (0 == Manager)) return 0;
    res = TimeManagerAdd(Manager, &obj);
    if (('r' == res) || ('k' == res))
    {
        ret_obj = TimeManagerCheck(Manager, &obj);
        return ret_obj;
    }
    else
    {


        return 
# 243 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 243 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  ;
    }
}

void TimeRegObjDestory(TimeManager* base, TimeRegObj* obj)
{
    if (obj != 
# 249 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 249 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  )
    {
        if (base == 
# 251 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                   0
# 251 "../Codes/MCU_Mold/MCU_TimeManager.c"
                       ) return;
        TimeManagerDelete(base, obj);
        obj = 
# 253 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
             0
# 253 "../Codes/MCU_Mold/MCU_TimeManager.c"
                 ;
    }
}

void TimeRegObjUpdataTime(TimeManager *Manager, TimeRegObj *obj, int time)
{
    if (obj == 
# 259 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 259 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  ) return;
    if (Manager == 
# 260 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
                  0
# 260 "../Codes/MCU_Mold/MCU_TimeManager.c"
                      ) return;

    obj->TimeReg = time;
    TimeManagerUpdataTime(Manager, obj, time);
}
void TimeManager_RunCount(TimeRegObj *obj, int count)
{
    if (obj == 
# 267 "../Codes/MCU_Mold/MCU_TimeManager.c" 3 4
              0
# 267 "../Codes/MCU_Mold/MCU_TimeManager.c"
                  ) return;

    obj->funcdoCount = count;
    obj->LoopCan = 'n';
}
